<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<h3 class="sub-header">分类管理</h3>
	<button class="btn btn-primary" data-toggle="modal" data-target="#addCategoryDiv">添加</button>
<div class="table-responsive">
	<table class="table">
		<thead>
			<tr>
				<th>序号</th>
				<th>名字</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${categoryPage.list}" var="category" varStatus="v">
			<tr class="active">
				<td>${v.count}</td>
			<td>${category.name}</td>
				<td>
					<button class="btn btn-default btn-xs  btn-danger" onclick="getCategory()">编辑</button>
					<button class="btn btn-default btn-xs  btn-danger" onclick="${ctx}/blog/deleteCategory?id=${discuss.id}">删除</button>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	</div>
	<ul class="pagination">
		<li><a href="#">&laquo;</a></li>
		<li class="active"><a href="#">1</a></li>
		<li><a href="#">2</a></li>
		<li><a href="#">3</a></li>
		<li><a href="#">4</a></li>
		<li><a href="#">5</a></li>
		<li><a href="#">&raquo;</a></li>
	</ul> 
		    <div class="modal fade" id="addCategoryDiv" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-dialog">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
		        <h4 class="modal-title" id="myModalLabel">新增分类</h4>
		      </div>
		      <div class="modal-body">
				<form class="form-horizontal" role="form" action="<%=request.getContextPath() %>/blog/addCategory" method="post">
				<input type="hidden" name="userId" value="${user.id }"/>
				  <div class="form-group">
				    <label for="name" class="col-sm-2 control-label">name</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" name="name">
				    </div>
				  </div>
				  <div class="form-group">
				    <div class="col-sm-offset-2 col-sm-10">
				      <button type="submit" class="btn btn-primary">新增</button>
				    </div>
				  </div>
				</form>
		      </div>
		    </div>
		  </div>
		</div>
	<script>
	function getCategory(id){
		 $("#updateUserForm").attr("action","<%=request.getContextPath()%>/sys/update");
		  $.ajax({  
		        type: "post",  
		        url: "<%=request.getContextPath()%>/sys/user/get/"+id,  
		        dataType: 'json',  
		        success: function(data) {  
		        	$("#username").val(data.username);
		        	$("#password").val(data.password);
		        	$("#code").val(data.code);
		        	$("#photo").val(data.photo);
		        	$("#id").val(data.id);
		        }  
		    });
		  $('#updateUserDiv').modal('show');  
	}


	</script>
